package com.health.tools;

import java.util.ArrayList;
import java.util.List;

import com.health.viewscontrols.NovaApplication;
import com.health.model.PeopleType;
import com.health.tablebean.ARCHIVE_BASEINFO;

import android.text.TextUtils;
import android.util.Log;
/**
 * 疾病人群处理
 * @author nova
 *
 */
public class JBRQData {
	public static final String TAG="JBRQData";
	/**
	 * 清空疾病人群分类
	 * 
	 * @author 王婷婷
	 * @date 2017年9月22日 上午11:54:07
	 */
	public static void clearGroup(String type, ARCHIVE_BASEINFO userInfo) {
		if (!TextUtils.isEmpty(userInfo.getPOPULATION_TYPE())) {
			String pop = userInfo.getPOPULATION_TYPE();
			if (!PeopleType.YBRQ.equals(pop)) {
				// 不是一般人群
				List<String> list = new ArrayList<String>();
				for (String t : pop.split(",")) {
					list.add(t);
				}

				if (!TextUtils.isEmpty(type)) {
					if (list.contains(type)) {
						list.remove(type);
					}
				} else {
					if (list.contains(PeopleType.GXY)) {
						list.remove(PeopleType.GXY);
					}
					if (list.contains(PeopleType.TNB)) {
						list.remove(PeopleType.TNB);
					}
					if (list.contains(PeopleType.GXB)) {
						list.remove(PeopleType.GXB);
					}
					if (list.contains(PeopleType.NCZ)) {
						list.remove(PeopleType.NCZ);
					}
					if (list.contains(PeopleType.JSB)) {
						list.remove(PeopleType.JSB);
					}
					if (list.contains(PeopleType.FJH)) {
						list.remove(PeopleType.FJH);
					}
					if (list.contains(PeopleType.CJR)) {
						list.remove(PeopleType.CJR);
					}
				}
				if (list.contains(PeopleType.YBRQ)) {
					list.remove(PeopleType.YBRQ);
				}
				String[] pops2 = list.toArray(new String[list.size()]);
				Log.e(TAG, "pops2()" + pops2.length);
				if (pops2.length == 0) {
					userInfo.setPOPULATION_TYPE(PeopleType.YBRQ);
				} else {
					pop = "";
					for (String s : pops2) {
						if (!TextUtils.isEmpty(s)) {
							if (TextUtils.isEmpty(pop)) {
								pop = s;
							} else {
								pop = pop + "," + s;
							}
						}
					}

					userInfo.setPOPULATION_TYPE(pop);
				}

			}

		} else {
			userInfo.setPOPULATION_TYPE(PeopleType.YBRQ);
		}

		Log.e(TAG, "clearGroup()" + userInfo.getPOPULATION_TYPE());
		NovaApplication.setUserInfo(userInfo);
		NovaApplication.fdbmanger.updata(userInfo);
		
	}
	/**
	 * 保存疾病
	 * 
	 * @author 王婷婷
	 * @date 2017年9月22日 下午3:05:53
	 */
	public static void saveJBLX(String peopleType, ARCHIVE_BASEINFO userInfo) {
	 
		
		if (!TextUtils.isEmpty(userInfo.getPOPULATION_TYPE())) {
			String pop = userInfo.getPOPULATION_TYPE();
			// String[] pops = pop.split(",");
			List<String> list = new ArrayList<String>();
			for (String t : pop.split(",")) {
				list.add(t);
			}

			if (!list.contains(peopleType)) {
				list.add(peopleType);
			}
			if (list.contains(PeopleType.YBRQ)) {
				list.remove(PeopleType.YBRQ);
			}
			String[] pops2 = list.toArray(new String[list.size()]);
			Log.e(TAG, "pops2()" + pops2.length);
			if (pops2.length == 0) {
				userInfo.setPOPULATION_TYPE(PeopleType.YBRQ);
			} else {
				pop = "";
				for (String s : pops2) {
					if (!TextUtils.isEmpty(s)) {
						if (TextUtils.isEmpty(pop)) {
							pop = s;
						} else {
							pop = pop + "," + s;
						}
					}

				}
				Log.e(TAG, "pop()" + pop);
				if (TextUtils.isEmpty(pop)) {
					userInfo.setPOPULATION_TYPE(PeopleType.YBRQ);
				} else {
					userInfo.setPOPULATION_TYPE(pop);
				}
			}

			// if (!Arrays.asList(pops).contains(peopleType)) {
			// pop = pop + "," + peopleType;
			// userInfo.setPOPULATION_TYPE(pop);
			// }
		} else {
			userInfo.setPOPULATION_TYPE(peopleType);
		}
		Log.e(TAG, "saveJBLX" + userInfo.getPOPULATION_TYPE());
		NovaApplication.setUserInfo(userInfo);
		NovaApplication.fdbmanger.updata(userInfo);
	
	}
}
